/**
 * inertiaCoeff:
 *      [
 *          _inertiaCoeff00,_inertiaCoeff01,_inertiaCoeff02,                0
 *          _inertiaCoeff10,_inertiaCoeff11,_inertiaCoeff12,                3
 *          _inertiaCoeff20,_inertiaCoeff21,_inertiaCoeff22,                6
 *      ]
 */
export default class Geometry {
    constructor(type) {
        this._type = type;
        this._volume = 0;
        this.inertiaCoeff=new Float64Array(9);
    }

    _updateMass() {
    }
    _computeAabb(aabb,tf) {
    }
    _rayCastLocal(beginX,beginY,beginZ,endX,endY,endZ,hit) {
        return false;
    }
    getType() {
        return this._type;
    }
    getVolume() {
        return this._volume;
    }
    rayCast(_begin,_end,_transform,hit) {
        let begin=_begin.elements,end=_end.elements,transform=_transform.elements;
        let beginLocalX = begin[0],beginLocalY = begin[1],beginLocalZ = begin[2];
        let endLocalX = end[0],endLocalY = end[1],endLocalZ = end[2];
        beginLocalX -= transform[0];beginLocalY -= transform[1];beginLocalZ -= transform[2];
        endLocalX -= transform[0];endLocalY -= transform[1];endLocalZ -= transform[2];
        beginLocalX = transform[3] * beginLocalX + transform[6] * beginLocalY + transform[9] * beginLocalZ;
        beginLocalY = transform[4] * beginLocalX + transform[7] * beginLocalY + transform[10] * beginLocalZ;
        beginLocalZ = transform[5] * beginLocalX + transform[8] * beginLocalY + transform[11] * beginLocalZ;
        endLocalX = transform[3] * endLocalX + transform[6] * endLocalY + transform[9] * endLocalZ;
        endLocalY = transform[4] * endLocalX + transform[7] * endLocalY + transform[10] * endLocalZ;
        endLocalZ = transform[5] * endLocalX + transform[8] * endLocalY + transform[11] * endLocalZ;
        if(this._rayCastLocal(beginLocalX,beginLocalY,beginLocalZ,endLocalX,endLocalY,endLocalZ,hit)) {
            let v = hit.position.elements;
            let localPosX = v[0],localPosY = v[1],localPosZ = v[2];
            let v1 = hit.normal.elements;
            let localNormalX = v1[0],localNormalY = v1[1],localNormalZ = v1[2];
            localPosX = transform[3] * localPosX + transform[4] * localPosY + transform[5] * localPosZ;
            localPosY = transform[6] * localPosX + transform[7] * localPosY + transform[8] * localPosZ;
            localPosZ = transform[9] * localPosX + transform[10] * localPosY + transform[11] * localPosZ;
            localNormalX = transform[3] * localNormalX + transform[4] * localNormalY + transform[5] * localNormalZ;
            localNormalY = transform[6] * localNormalX + transform[7] * localNormalY + transform[8] * localNormalZ;
            localNormalZ = transform[9] * localNormalX + transform[10] * localNormalY + transform[11] * localNormalZ;
            localPosX += transform[0];localPosY += transform[1];localPosZ += transform[2];
            v[0] = localPosX;v[1] = localPosY;v[2] = localPosZ;
            v1[0] = localNormalX;v1[1] = localNormalY;v1[2] = localNormalZ;
            return true;
        }
        return false;
    }
}